# -*- coding: utf-8 -*-
# @Author : HaleShi
# @Time : 2023-05-16
# @File : 7.java字节转16进制.py

import random


def generate_py39():
    data = random.randbytes(10)  # pytho3.9才能使用

    ele_list = []
    for item in data:
        # 184    十进制  -> 十六进制
        # hex(item)  #
        ele = hex(item)[2:]
    res = "".join(ele_list)
    print(res)

    # data = "".join([ hex(item)[2:] for item in random.randbytes(10)])

    # 注意，有些逆向可能不足两位数的，会补足
    data = random.randbytes(10)  # pytho3.9

    ele_list = []
    for item in data:
        ele = hex(item)[2:].rjust(2, "0")
    res = "".join(ele_list)
    print(res)

    # data = "".join([ hex(item)[2:].rjust(2,"0") for item in random.randbytes(10)])


def generate_py_old():
    # python3.9之前版本生成16进制
    data = "".join([hex(random.randint(0, 255))[2:] for i in range(4)])
    print(data)


def run():
    # python3.9之前版本生成16进制
    generate_py_old()

    # python3.9生成16进制
    # generate_py39()


if __name__ == '__main__':
    run()
